# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer:
pkgname=ocaml-ppx_gen_rec
_pkgname=ppx_gen_rec
pkgver=1.0.0
pkgrel=1
pkgdesc="OCaml preprocessor that generates a recursive module"
url="https://github.com/flowtype/ocaml-ppx_gen_rec"
arch="all !x86 !armhf !armv7 !s390x !mips !mips64"  # limited by ocaml aport
license="MIT"
depends="ocaml-runtime ocaml-migrate-parsetree"
makedepends="dune ocaml ocaml-compiler-libs ocaml-findlib ocaml-migrate-parsetree-dev opam"
options="!check"  # no tests provided
subpackages="$pkgname-dev"
source="https://github.com/flowtype/$pkgname/archive/v$pkgver/$pkgname-$pkgver.tar.gz"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	jbuilder build @install
}

package() {
	cd "$builddir"

	mkdir -p "$pkgdir"/usr/lib/ocaml
	jbuilder install \
		--destdir="$pkgdir/usr" \
		--libdir="$pkgdir/usr/lib/ocaml"

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc

	# Remove annotation files and sources.
	cd "$pkgdir"/usr/lib/ocaml/$_pkgname
	rm -f *.cmt* *.ml
}

dev() {
	default_dev

	depends="$pkgname=$pkgver-r$pkgrel"
	local sitelib="usr/lib/ocaml/$_pkgname"

	cd "$pkgdir"/$sitelib

	mkdir -p "$subpkgdir"/$sitelib
	mv *.cmx *.cmxa *.mli "$subpkgdir"/$sitelib/
}

sha512sums="7eb5f131646e984e7e5bd2765604f532772bb2f706fec607581ee10f1ebae4ffb3e032da93550c1ffa7e024690ed06bc2d7355cf66949198ec853ac60fdd5a8e  ocaml-ppx_gen_rec-1.0.0.tar.gz"
